﻿using System;
using fc2editor.DataModel.Descriptors;

namespace fc2editor.DataModel
{
    public class Weapon
    {
        #region Properties

        public WeaponsCategory Category
        {
            get
            {
                return descriptor.Category;
            }
        }

        public Guid ID
        {
            get
            {
                return descriptor.ID;
            }
        }

        public string Name
        {
            get
            {
                return descriptor.Name;
            }
        }

        public string Picture
        {
            get
            {
                return descriptor.Picture;
            }
        }

        public byte[] PictureData { get; private set; }

        public bool IsGuided
        {
            get
            {
                return descriptor.IsGuided;
            }
        }

        public Pylon Parent { get; private set; }

        #endregion

        public Weapon(WeaponDescriptor descriptor)
        {
            if (descriptor == null)
                throw new NullReferenceException("Illegal null-reference descriptor");

            this.descriptor = descriptor;
        }

        public override string ToString()
        {
            return Name;
        }

        /// <summary>
        /// Deeply clones current weapon except Parent property
        /// </summary>
        /// <returns></returns>
        public Weapon Clone()
        {
            var descriptor = new WeaponDescriptor()
            {
                Category = Category,
                ID = ID,
                Name = Name,
                Picture = Picture,
                IsGuided = IsGuided
            };

            var clone = new Weapon(descriptor);
            clone.SetPictureData(PictureData);
            return clone;
        }

        internal void SetPictureData(byte[] data)
        {
            PictureData = data;
        }

        internal void SetParent(Pylon pylon)
        {
            Parent = pylon;
        }

        private WeaponDescriptor descriptor;
    }
}
